import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '../store/index'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Home,
    children: [
      {
        path: '',
        component: () => import('../views/home/index.vue'),
      },
      {
        path: 'msbd',
        name: 'msbd',
        component: () => import('../views/msbd/msbd.vue')
      },
      {
        path: 'setting',
        component: () => import('../views/sz/Setting.vue')
      },
      {
        path: 'exam',
        component: () => import('../views/ks/examination.vue')
      },
      {
        path: '/details/:id',
        name: 'details',
        component: () => import('../views/msbd/details.vue'),
        props: true
      }
    ]
  },
  {
    path: '/login',
    component: () => import('../views/login/login.vue')
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue'),
  }
  // }
  // {
  //   path: '/details/:id',
  //   name: 'details',
  //   component: () => import('../views/msbd/details.vue'),
  //   props: true
  // }
]

const router = new VueRouter({
  routes
})

let whiteList=['/setting','/login']

router.beforeEach((to,from,next)=>{
  if(whiteList.includes(to.path)){
    next()
  }else{
    if(store.state.users.list.id){
      next()
    }else{
      next('/setting')
    }
  }
})



export default router
